package com.chen.framework.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.framework.model.auth.AuthPermission;
import com.chen.framework.mapper.AuthPermissionMapper;
import com.chen.framework.service.inter.AuthPermissionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author: ~龙~
 * @date: 2023/6/13 17:14
 **/
@Slf4j
@Service
@AllArgsConstructor
public class AuthPermissionServiceImpl extends ServiceImpl<AuthPermissionMapper, AuthPermission> implements AuthPermissionService {

    @Override
    public Set<String> getPermissionCodeSet(Set<Long> permissionIdSet) {
        if (CollectionUtil.isEmpty(permissionIdSet)){
            return new HashSet<>();
        }
        return list(
                Wrappers.lambdaQuery(AuthPermission.class)
                        .select(AuthPermission::getCode)
                        .in(AuthPermission::getPermissionId, permissionIdSet)
        ).stream().map(AuthPermission::getCode).collect(Collectors.toSet());
    }


}
